package cn.iocoder.yudao.module.xiaoBizHandler.service.codegen.newInner.yudao.template.java.service;

import cn.iocoder.yudao.framework.common.genCode.common.StringBuilderHandler;
import cn.iocoder.yudao.module.xiaoBizHandler.dal.dataobject.codegen.XiaoBizHandlerCodegenColumnDO;
import cn.iocoder.yudao.module.xiaoBizHandler.dal.dataobject.codegen.XiaoBizHandlerCodegenTableDO;
import cn.iocoder.yudao.module.xiaoBizHandler.service.codegen.newInner.yudao.handler.PathHandler;
import cn.iocoder.yudao.module.xiaoBizHandler.service.codegen.newInner.yudao.template.CodeGenTemplate;
import cn.iocoder.yudao.module.xiaoBizHandler.service.codegen.newInner.GlobalBinding;
import cn.iocoder.yudao.module.xiaoBizHandler.service.codegen.newInner.LocalBinding;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class Service implements CodeGenTemplate {

    public String getPath(XiaoBizHandlerCodegenTableDO table, List<XiaoBizHandlerCodegenColumnDO> columns, GlobalBinding globalBinding, LocalBinding localBinding, XiaoBizHandlerCodegenColumnDO primaryColumn) {
        PathHandler pathHandler = PathHandler.builder()
                .table(table)
                .columns(columns)
                .globalBinding(globalBinding)
                .localBinding(localBinding)
                .primaryColumn(primaryColumn)
                .build();
        return pathHandler.javaModuleImplMainFilePath("service/" + table.getBusinessName() + "/" + table.getClassName() + "Service");
    }


    public String render(XiaoBizHandlerCodegenTableDO table, List<XiaoBizHandlerCodegenColumnDO> columns, GlobalBinding globalBinding, LocalBinding localBinding, XiaoBizHandlerCodegenColumnDO primaryColumn) {
        StringBuilderHandler code = new StringBuilderHandler();
        code.apAndBl("package " + globalBinding.getBasePackage() + ".module." + table.getModuleName() + ".service." + table.getBusinessName() + ";");
        code.bl();
        code.apAndBl("import java.util.*;");
        code.apAndBl("import javax.validation.*;");
        code.apAndBl("import " + globalBinding.getBasePackage() + ".module." + table.getModuleName() + ".controller." + localBinding.getSceneEnum().getBasePackage() + "." + table.getBusinessName() + ".vo.*;");
        code.apAndBl("import " + globalBinding.getBasePackage() + ".module." + table.getModuleName() + ".dal.dataobject." + table.getBusinessName() + "." + table.getClassName() + "DO;");
        code.apAndBl("import " + globalBinding.getPageResultClassName() + ";");
        code.bl();
        code.apAndBl("/**");
        code.apAndBl(" * " + table.getClassComment() + " Service 接口");
        code.apAndBl(" *");
        code.apAndBl(" * @author " + table.getAuthor() + "");
        code.apAndBl(" */");
        code.apAndBl("public interface " + table.getClassName() + "Service {");
        code.bl();
        code.apAndBl("    /**");
        code.apAndBl("     * 创建" + table.getClassComment() + "");
        code.apAndBl("     *");
        code.apAndBl("     * @param createReqVO 创建信息");
        code.apAndBl("     * @return 编号");
        code.apAndBl("     */");
        code.apAndBl("    " + primaryColumn.getJavaType() + " create" + localBinding.getSimpleClassName() + "(@Valid " + localBinding.getSceneEnum().getPrefixClass() + "" + table.getClassName() + "CreateReqVO createReqVO);");
        code.bl();
        code.apAndBl("    /**");
        code.apAndBl("     * 更新" + table.getClassComment() + "");
        code.apAndBl("     *");
        code.apAndBl("     * @param updateReqVO 更新信息");
        code.apAndBl("     */");
        code.apAndBl("    void update" + localBinding.getSimpleClassName() + "(@Valid " + localBinding.getSceneEnum().getPrefixClass() + "" + table.getClassName() + "UpdateReqVO updateReqVO);");
        code.bl();
        code.apAndBl("    /**");
        code.apAndBl("     * 删除" + table.getClassComment() + "");
        code.apAndBl("     *");
        code.apAndBl("     * @param id 编号");
        code.apAndBl("     */");
        code.apAndBl("    void delete" + localBinding.getSimpleClassName() + "(" + primaryColumn.getJavaType() + " id);");
        code.bl();
        code.apAndBl("    /**");
        code.apAndBl("     * 获得" + table.getClassComment() + "");
        code.apAndBl("     *");
        code.apAndBl("     * @param id 编号");
        code.apAndBl("     * @return " + table.getClassComment() + "");
        code.apAndBl("     */");
        code.apAndBl("    " + table.getClassName() + "DO get" + localBinding.getSimpleClassName() + "(" + primaryColumn.getJavaType() + " id);");
        code.bl();
        code.apAndBl("    /**");
        code.apAndBl("     * 获得" + table.getClassComment() + "列表");
        code.apAndBl("     *");
        code.apAndBl("     * @param ids 编号");
        code.apAndBl("     * @return " + table.getClassComment() + "列表");
        code.apAndBl("     */");
        code.apAndBl("    List<" + table.getClassName() + "DO> get" + localBinding.getSimpleClassName() + "List(Collection<" + primaryColumn.getJavaType() + "> ids);");
        code.bl();
        code.apAndBl("    /**");
        code.apAndBl("     * 获得" + table.getClassComment() + "分页");
        code.apAndBl("     *");
        code.apAndBl("     * @param pageReqVO 分页查询");
        code.apAndBl("     * @return " + table.getClassComment() + "分页");
        code.apAndBl("     */");
        code.apAndBl("    PageResult<" + table.getClassName() + "DO> get" + localBinding.getSimpleClassName() + "Page(" + localBinding.getSceneEnum().getPrefixClass() + "" + table.getClassName() + "PageReqVO pageReqVO);");
        code.bl();
        code.apAndBl("    /**");
        code.apAndBl("     * 获得" + table.getClassComment() + "列表, 用于 Excel 导出");
        code.apAndBl("     *");
        code.apAndBl("     * @param exportReqVO 查询条件");
        code.apAndBl("     * @return " + table.getClassComment() + "列表");
        code.apAndBl("     */");
        code.apAndBl("    List<" + table.getClassName() + "DO> get" + localBinding.getSimpleClassName() + "List(" + localBinding.getSceneEnum().getPrefixClass() + "" + table.getClassName() + "ExportReqVO exportReqVO);");
        code.bl();
        code.apAndBl("}");
        code.bl();
        return code.toString();
    }

}